package com.woniuxy.threeproject.end_water_project_user.commons;
import com.woniuxy.threeproject.end_water_project_user.domain.Meterreading;
import com.woniuxy.threeproject.end_water_project_user.domain.PaymentDetail;
import com.woniuxy.threeproject.end_water_project_user.domain.User;
import com.woniuxy.threeproject.end_water_project_user.service.IMeterreadingService;
import com.woniuxy.threeproject.end_water_project_user.service.IUserService;
import com.woniuxy.threeproject.end_water_project_user.service.impl.MeterreadingServiceImpl;
import com.woniuxy.threeproject.end_water_project_user.service.impl.UserServiceImpl;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Slf4j
public class LateFeeCal {

    public static Double lateFeeNo(Meterreading waterNum){
        Long day = 1L;
        int lateDay = 0;
        day = (new Date().getTime() - waterNum.getLastMeterTime().getTime()) / (1000 * 60 * 60 * 24) - 40;
        log.info("上次抄表日间隔时间为：{}", day);
//                到结算日起算 超过出账单日10天（30+10）天每天计收1毛
        if (day > 0) {
            lateDay += day;
        }
        return  lateDay * 0.1;
    }

    //滞纳金
    public static Double lateFee(List<Meterreading> waterNums) {
        if (waterNums.size() > 0) {
            Date now = new Date();
            Long day = 1L;
//            表示延迟天数，
            double lateDay = 0.0;
            for (int i = 0; i < waterNums.size(); i++) {
                lateDay += lateFeeNo(waterNums.get(i));
            }
            return lateDay;
        }
        return 0.00;
    }

    public static Double waterNumtotal(List<Meterreading> meterreadings) {
        Double water = 0.00;
        int length = meterreadings.size();
        for (int i = 0; i < length; i++) {
            Meterreading meter = meterreadings.get(i);
            water += meter.getWaterNum();
        }
        return water;
    }

    public static Double waterNumtotalP(List<PaymentDetail> paymentDetails){
        Double water = 0.00;
        int length = paymentDetails.size();
        for (int i = 0; i < length; i++) {
            PaymentDetail paymentDetail = paymentDetails.get(i);
            water += paymentDetail.getWaterNum();
        }
        return water;
    }


}
